#include "Com_Mod.h"
#include <Windows.h>
#include <iostream>

using namespace std;

void Communicator::Setup(){

	cout << "Configurating communicator" << endl;

	// Base serial settings
	serial_port_base::baud_rate BAUD(9600);
	serial_port_base::flow_control FLOW( serial_port_base::flow_control::none );
	serial_port_base::parity PARITY( serial_port_base::parity::none );
	// serial_port_base::stop_bits STOP( serial_port_base::stop_bits::one );
	serial_port_base::stop_bits STOP( serial_port_base::stop_bits::one );

	// Setup port - base settings
	port.set_option( BAUD );
	port.set_option( FLOW );
	port.set_option( PARITY );
	port.set_option( STOP );

	cout << "Configurating communicator done" << endl;;

};

void Communicator::Send2(){

};

void Communicator::Send(int X, int Y, int AngleX, int AngleY){

	SendData.Struc.Y = Y;
	SendData.Struc.X = X;
	SendData.Struc.AngleY = AngleY;
	SendData.Struc.AngleX = AngleX;

    for(int i=0; i < sizeof(SendData); i++){
		write(port,buffer((unsigned char*)&SendData.bytes[i], 1));
	};
};

void Communicator::Recieve(){

    RecvData.Struc.Y = 0;
	RecvData.Struc.X = 0;
	RecvData.Struc.AngleY = 0;
	RecvData.Struc.AngleX = 0;

    for(int i=0; i < sizeof(RecvData); i++){
		if (read(port,buffer((unsigned char*)&RecvData.bytes[i], 1)) == 0)
		{
			break;
		}
	};
};


void Communicator::Read(char* Buffer){


};


